//var auth = require('auth');

function getData(options){
    var action = options['action'];
    var lastId = options['lastId'];
    var url = 'https://v1.wx91go.com/index.php?m=Api&c=WxMini&a=' + action;

    if (lastId) {
        url += '&last_id='+lastId
    }

    var session3rd = wx.getStorageSync('session3rd');
    if (session3rd) {
        url += '&session3rd='+session3rd;
    }

    

    options['url'] = url;

    options.data = options.data || {};

    var wecha_id = wx.getStorageSync('wecha_id');
    // if (wecha_id) {
    //     url += '&wecha_id='+wecha_id;
    // }

    if (!options.data['wecha_id']) {
        options.data['wecha_id'] = wecha_id;
    }
    wx.request(options);
}

function request(options){

    wx.checkSession({
        success:function () {
            getData(options);
        },
        fail:function () {
            // auth.login(function(){
            //     getData(options);
            // });
        }
    });
    
}

module.exports = {
    request:request
}